package com.example.zwh.computershop.classify;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.zwh.computershop.R;
import com.example.zwh.computershop.handleDataClient.handleData;
import com.example.zwh.computershop.sqlModel.Product;

import java.util.List;

public class ClassifyShowAdapter extends RecyclerView.Adapter<ClassifyShowAdapter.ViewHolder> {
    private List<Product> mShowList;

    static class ViewHolder extends RecyclerView.ViewHolder {
        ImageView iv_view;
        TextView text_title;
        TextView text_price;
        public ViewHolder (View view) {
            super(view);
            iv_view = view.findViewById(R.id.iv_view);
            text_title = view.findViewById(R.id.text_title);
            text_price = view.findViewById(R.id.text_price);
        }
    }

    public ClassifyShowAdapter(List<Product> mShowList) {
        this.mShowList = mShowList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.classify_pro_item, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Product classify_show = mShowList.get(position);
        holder.iv_view.setImageResource(handleData.getResourceByReflect(classify_show.getImgUrl()));
        holder.text_title.setText(classify_show.getProductInfor());
        holder.text_price.setText(String.valueOf(classify_show.getPrice()));
    }
    @Override
    public int getItemCount() {
        return mShowList.size();
    }
    public void setmShowList(List<Product> mShowList) {
        this.mShowList = mShowList;
        notifyDataSetChanged();
    }


}
